package xmath

func BinarySearch(array []int, value int) int {
	var low = 0
	var high = len(array) - 1

	for low <= high {
		var middle = low + ((high - low) >> 1)
		var midValue = array[middle]

		if midValue == value {
			return middle
		} else if midValue > value {
			high = middle - 1
		} else {
			low = middle + 1
		}
	}

	return ^low
}

func Max(a , b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func Min(a , b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func AbsInt(v int) int {
	if v < 0 {
		return -v
	}
	return v
}